
             
/**
 * 
 *
 * Copyright (c) 2012-2013 JLLT Corp. 2012-2013,All Rights Reserved.
 * This software is published under the 金麟龙腾商贸有限公司.
 * License version 1.0, a copy of which has been included with this
 * distribution in the LICENSE.txt file. 
 *
 * @File name:  QueryTProductCategoryByKeywordAction.java   查询【商品信息:T_PRODUCT】
 * @Create on:  2012-07-30 23:08:506
 * @Author      :  高宇舟
 *
 * @ChangeList
 * ---------------------------------------------------
 * Date         Editor              ChangeReasons
 *
 */
           
        package com.boho.ecp.product.action;

            
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeSet;

import cn.boho.framework.actions.ActionImp;
import cn.boho.framework.context.ActionContext;
import cn.boho.framework.po.DynaBeanMap;
import cn.boho.framework.service.MessageService;

import com.boho.ecp.base.cache.TCategoryCache;
import com.boho.ecp.po.TCategoryPO;
import com.boho.ecp.product.cache.TProductCache;
import com.boho.ecp.util.MatchUtils;
public class QueryTProductCategoryByKeywordAction extends ActionImp {
	private Connection con=null;
	@Override
	protected void doException(ActionContext atx, Exception ex) {
		atx.setErrorContext("EC_COMMON_1004", MessageService.getMessage("EC_COMMON_1004"),"【商品信息:T_PRODUCT|】" ,ex);
	}
	@Override
	protected int performExecute(ActionContext atx) throws Exception {
		String productKeyword = atx.getStringValue("PRODUCT_KEYWORD");
		String categoryId = atx.getStringValue("CATEGORY_ID");
		String categories = "";
		if (!MatchUtils.isEmpty(categoryId)) {
			StringBuffer sb = new StringBuffer();
			sb.append(categoryId).append(",");
			List<TCategoryPO> childList = TCategoryCache.queryTCategoryForTreeMode(con, Integer.parseInt(categoryId), 4);
//			List<TCategoryPO> childList = TCategoryDao.queryTCategoryForTreeMode(con, Integer.parseInt(categoryId), 4);
			for (TCategoryPO categoryPO : childList) {
				sb.append(categoryPO.getCategoryId()).append(",");
			}
			if (sb.lastIndexOf(",") != -1) {
				categories = sb.substring(0, sb.length()-1);
			}
		}
//		List list = TProductDao.queryTProductByKeyword(con,productKeyword,categories);
		List list = TProductCache.queryTProductByKeyword(con,productKeyword,categories);
		List categoryList = new ArrayList();
		for (int i=0; i<list.size(); i++) {
			DynaBeanMap dbm = (DynaBeanMap) list.get(i);
			if (!MatchUtils.isEmpty(dbm.get("CATEGORY_NAME"))) {
				categoryList.add(dbm.get("CATEGORY_NAME"));
			}
		}

		TreeSet categorySet = new TreeSet(categoryList);
		categoryList.clear();
		categoryList.addAll(categorySet);
		
		atx.setValue("T_CATEGORY", categoryList.toArray());
		return 1;
	}
	@Override
	protected int verifyParameters(ActionContext atx) throws Exception {
		con = atx.getConection();
		return 1;
	}
}
